import time

import allure
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support import expected_conditions

from tests.app.pages.delete_confirmation_page import DeleteConfirmationPage
from tests.app.pages.wecom import Wecom
from tests.app.utils.log_util import logger


class EditMemberPage(Wecom):
    __DELETE_MEMBER = AppiumBy.XPATH, '//*[@text = "删除成员"]'
    __FAIL_TITLE = AppiumBy.ID, "//*[@text = '删除成员']/../..//*[@class = 'android.widget.ScrollView']/child::*"

    @allure.step("点击删除成员按钮")
    def click_delete_member_button(self):
        delete_button = self.swip_find(self.__DELETE_MEMBER)
        logger.warning("delete_button: " + str(delete_button))
        delete_button.click()
        return DeleteConfirmationPage(self.driver)

    @allure.step("点击删除成员按钮")
    def fail_click_delete_member_button(self):
        delete_button = self.swip_find(self.__DELETE_MEMBER)
        logger.warning("delete_button: " + str(delete_button))
        delete_button.click()
        return self

    def get_fail_title(self):
        with allure.step("获取失败提示"):
            fail_title = self.find(*self.__FAIL_TITLE)
        return fail_title.text
